import { http } from "@/utils/http";
import type { HttpResponse } from "types/request";
import { URL_PREFIX } from "./constants";

export type RiskRuleSchema = {
  name: string;
  trade_app_name: string;
  template: string;
  arguments: Record<string, any>;
  enabled: boolean;
  gateway_name?: string;
};

export type RiskTemplateMetadataSchema = {
  template: string;
  docstring: string;
  argument_schema: Record<string, any>;
};

export function getRiskRules() {
  return http.request<HttpResponse<RiskRuleSchema[]>>(
    "get",
    `${URL_PREFIX}/risk/rules`
  );
}

export function createOrUpdateRiskRule(data: RiskRuleSchema) {
  return http.request<HttpResponse<RiskRuleSchema>>(
    "post",
    `${URL_PREFIX}/risk/rules`,
    {
      data
    }
  );
}

export function deleteRiskRule(name: string) {
  return http.request<HttpResponse<string>>(
    "delete",
    `${URL_PREFIX}/risk/rules/${name}`
  );
}

export function getRiskTemplates() {
  return http.request<HttpResponse<RiskTemplateMetadataSchema[]>>(
    "get",
    `${URL_PREFIX}/risk/rules/templates`
  );
}
